package org.huawei260.TiKu.ODsuanfa;

/**
 * @Author: qingle
 * @Date: 2024/10/28-16:11
 * @Description: 3112 【贪心】2023B-判断字符串子序列
 * @version: 1.0
 */
import java.util.Scanner;
public class B_2023B_3112__贪心_判断字符串子序列 {

//	public class Main {
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);

			System.out.println(getResult(sc.nextLine(), sc.nextLine()));
		}

		public static int getResult(String target, String source) {
			int cursor = target.length() - 1;
			for (int i = source.length() - 1; i >= 0; i--) {
				if (source.charAt(i) == target.charAt(cursor)) {
					cursor--;
					if (cursor < 0) return i;
				}
			}

			return -1;
		}
	}